﻿using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;

namespace JIG_SoftTemplate.Resources.Style
{
    public class JudgeBlock : ContentControl
    {

        //状态判定（OK/NG)
        public bool IsOK
        {
            get { return (bool)GetValue(IsOKProperty); }
            set { SetValue(IsOKProperty, value); }
        }

        // Using a DependencyProperty as the backing store for IsOK.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty IsOKProperty =
            DependencyProperty.Register("IsOK", typeof(bool), typeof(JudgeBlock), new PropertyMetadata(true, OnIsOKChanged));


        //是否清空判定状态
        public bool IsShowJudge
        {
            get { return (bool)GetValue(IsShowJudgeProperty); }
            set { SetValue(IsShowJudgeProperty, value); }
        }

        // Using a DependencyProperty as the backing store for IsShowJudge.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty IsShowJudgeProperty =
            DependencyProperty.Register("IsShowJudge", typeof(bool), typeof(JudgeBlock), new PropertyMetadata(true, OnIsShowJudgeChanged));


        private static void OnIsShowJudgeChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            JudgeBlock JudgeBlock = d as JudgeBlock;
            JudgeBlock.Visibility = JudgeBlock.IsShowJudge ? Visibility.Visible : Visibility.Hidden;
        }



        public CornerRadius CornerRadius
        {
            get { return (CornerRadius)GetValue(CornerRadiusProperty); }
            set { SetValue(CornerRadiusProperty, value); }
        }

        // Using a DependencyProperty as the backing store for CornerRadius.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty CornerRadiusProperty =
            DependencyProperty.Register("CornerRadius", typeof(CornerRadius), typeof(JudgeBlock));




        private static void OnIsOKChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            JudgeBlock? JudgeBlock = d as JudgeBlock;
            if (JudgeBlock.IsOK == true)
            {
                JudgeBlock.Content = "OK";
                JudgeBlock.Background = (Brush)Application.Current.Resources["Color_OK"];

            }
            else
            {
                JudgeBlock.Content = "NG";
                JudgeBlock.Background = (Brush)Application.Current.Resources["Color_NG"];
            }
        }
    }
}
